package com.jinlia.show.modules.system.service;

import com.jinlia.show.modules.base.constant.PayForTypeEnum;
import com.jinlia.show.modules.base.model.po.OrderPO;
import com.jinlia.show.modules.base.system.entity.DeliveryOrder;
import com.jinlia.show.modules.base.system.service.DeliveryOrderMapperService;
import com.jinlia.show.modules.base.system.service.OrderMapperService;
import com.jinlia.show.modules.base.wxapp.entity.PayOrder;
import com.jinlia.show.modules.base.wxapp.service.PayOrderMapperService;
import com.jinlia.show.modules.system.model.vo.OrderPrinter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class OrderPrinterService {

    @Autowired
    OrderMapperService orderMapperService;
    @Autowired
    PayOrderMapperService payOrderMapperService;
    @Autowired
    DeliveryOrderMapperService deliveryOrderMapperService;

    public OrderPrinter getOrderPrinter(Long saleOrderId) {
        OrderPrinter orderPrinter = new OrderPrinter();
        OrderPO orderPO = orderMapperService.getPOByIds(saleOrderId).get(0);
        orderPrinter.setOrder(orderPO);
        List<PayOrder> listPayOrder = payOrderMapperService.lambdaQuery()
                .eq(PayOrder::getPayForId, saleOrderId)
                .eq(PayOrder::getPayForType, PayForTypeEnum.SALE.getValue())
                .list();
        orderPrinter.setPayOrderList(listPayOrder);
        DeliveryOrder oneDeliveryOrder = deliveryOrderMapperService.lambdaQuery()
                .eq(DeliveryOrder::getOrderId, saleOrderId)
                .one();
        orderPrinter.setDeliveryOrder(oneDeliveryOrder);
        return orderPrinter;
    }
}
